<template>
    <view>
        <view class="from">
            <view class="from-item">
                <view class="font-30">{{ $t('bankAddPage.name') }}</view>
                <input type="text" v-model="from.realname" class="font-30" :placeholder="$t('bankAddPage.namePlaceholder')" placeholder-class="D7" />
            </view>
            <view class="from-item">
                <view class="font-30">{{ $t('bankAddPage.idCard') }}</view>
                <input type="idcard" v-model="from.idcard" class="font-30" :placeholder="$t('bankAddPage.idCardPlaceholder')" placeholder-class="D7" />
            </view>
            <view class="from-item">
                <view class="font-30">{{ $t('bankAddPage.bankAccountNumber') }}</view>
                <input type="number" v-model="from.bank_card" class="font-30" :placeholder="$t('bankAddPage.bankAccountNumberPlaceholder')" placeholder-class="D7" />
            </view>
            <picker :range="bank_list" range-key="bankname" @change="bank_change">
                <view class="from-item">
                    <view class="font-30">{{ $t('bankAddPage.openingBank') }}</view>
                    <view class="more font-30">{{ bank_text }}</view>
                    <!-- <input type="text" v-model="from.bank_branch" class="font-30" placeholder="请输入开户行名称" placeholder-class="D7"> -->
                </view>
            </picker>
            <view class="from-item">
                <view class="font-30">{{ $t('bankAddPage.bankBranch') }}</view>
                <input type="text" v-model="from.bank_branch" class="font-30" :placeholder="$t('bankAddPage.openingBankPlaceholder')" placeholder-class="D7" />
            </view>
            <view class="from-item">
                <view class="font-30">{{ $t('bankAddPage.phoneNumber') }}</view>
                <input type="number" v-model="from.mobile" class="font-30" :placeholder="$t('bankAddPage.phoneNumberPlaceholder')" placeholder-class="D7" />
            </view>
        </view>
        <view class="button font-30" :class="[$i18n.locale]" @tap="input_password">{{ $t('confirm') }}</view>
        <pay-password ref="pay" v-model="pay_dialog" :show="false" @check_word="save"></pay-password>
    </view>
</template>

<script>
import payPassword from 'index/components/pay_password.vue'
export default {
    data() {
        return {
            from: {
                bank_type: 1,
                realname: '',
                idcard: '',
                bank_branch: '',
                mobile: '',
                bank_card: '',
                bank_name: '',
                paypwd: ''
            },
            pay_dialog: false,
            bank_list: [],
            bank_text: this.$t('bankAddPage.openingBankPlaceholder')
        }
    },
    onLoad() {
        uni.setNavigationBarTitle({
            title: this.$t('bankAddPage.navigationBarTitle')
        })
    },
    mounted() {
        this.$http('get|api/User/add_bankcard').then(res => {
            this.bank_list = res.result.bank_type
        })
    },
    methods: {
        input_password() {
            if (!this.from.realname) {
                this.$toastApp(this.$t('bankAddPage.namePlaceholder'))
                return
            }
            if (!this.from.idcard) {
                this.$toastApp(this.$t('bankAddPage.idCardPlaceholder'))
                return
            }
            if (!this.from.bank_card) {
                this.$toastApp(this.$t('bankAddPage.bankAccountNumberPlaceholder'))
                return
            }
            if (!this.from.bank_name) {
                this.$toastApp(this.$t('bankAddPage.openingBankPlaceholder'))
                return
            }
            if (!this.from.bank_branch) {
                this.$toastApp(this.$t('bankAddPage.bankBranchPlaceholder'))
                return
            }
            if (!this.from.mobile) {
                this.$toastApp(this.$t('bankAddPage.phoneNumberPlaceholder'))
                return
            }
            this.pay_dialog = true
        },
        save(e) {
            this.from.paypwd = e
            this.$http('post|api/User/add_bankcard', this.from)
                .then(res => {
                    this.$toastApp(res.msg)
                    setTimeout(() => {
                        uni.navigateBack()
                    }, 1000)
                })
                .catch(e => {
                    this.$toastApp(e.msg)
                    this.$refs.pay.passworld = []
                })
        },
        bank_change(e) {
            let index = e.target.value
            this.bank_text = this.bank_list[index].bankname
            this.from.bank_name = this.bank_list[index].id
        }
    },
    components: {
        payPassword
    }
}
</script>

<style lang="scss">
.from {
    padding: 0 30rpx;
    box-sizing: border-box;
    .from-item {
        height: 100rpx;
        display: flex;
        justify-content: space-between;
        align-items: center;
        box-shadow: 0px 1rpx 0px 0px rgba(223, 227, 230, 1);
        margin-top: 2rpx;
        input {
            text-align: right;
        }
    }
    .D7 {
        color: #d7d7d9;
    }
}
.button {
    width: 690rpx;
    height: 100rpx;
    // background: rgba(51, 135, 255, 1);
    border-radius: 45rpx;
    margin: 0 auto;
    margin-top: 60rpx;
    text-align: center;
    line-height: 90rpx;
    color: #ffffff;
}
.more {
    padding-right: 40rpx;
    position: relative;
}
.more::after {
    position: absolute;
    height: 36rpx;
    width: 36rpx;
    background-image: url(../../../static/more.png);
    background-size: 100%;
    right: 0;
    top: 50%;
    margin-top: -18rpx;
    content: '';
}
</style>
